package com.turnengine.client.local.location.bean;

import com.turnengine.client.local.location.enums.LocationSignup;
import com.turnengine.client.local.unit.bean.IUnitCount;
import java.util.List;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Location.
 */
public class Location implements ILocation, Comparable<ILocation> {

	/** The id. */
	private int id = -1;
	/** The name. */
	private String name = "";
	/** The group id. */
	private int groupId = -1;
	/** The player id. */
	private int playerId = -1;
	/** The signup. */
	private LocationSignup signup = LocationSignup.SIGNUP;
	/** The signup faction id. */
	private int signupFactionId = -1;
	/** The coordinates. */
	private int[] coordinates = null;
	/** The location unit list. */
	private List<IUnitCount> locationUnitList;
	/** The mobile unit list. */
	private List<IUnitCount> mobileUnitList;

	/**
	 * Creates a new Location.
	 */
	public Location() {
	}

	/**
	 * Creates a new Location.
	 * @param id the id
	 * @param name the name
	 * @param groupId the group id
	 * @param playerId the player id
	 * @param signup the signup
	 * @param signupFactionId the signup faction id
	 * @param coordinates the coordinates
	 * @param locationUnitList the location unit list
	 * @param mobileUnitList the mobile unit list
	 */
	public Location(int id, String name, int groupId, int playerId, LocationSignup signup, int signupFactionId, int[] coordinates, List<IUnitCount> locationUnitList, List<IUnitCount> mobileUnitList) {
		setId(id);
		setName(name);
		setGroupId(groupId);
		setPlayerId(playerId);
		setSignup(signup);
		setSignupFactionId(signupFactionId);
		setCoordinates(coordinates);
		setLocationUnitList(locationUnitList);
		setMobileUnitList(mobileUnitList);
	}

	/**
	 * Creates a new Location.
	 * @param location the location
	 */
	public Location(Location location) {
		setId(location.getId());
		setName(location.getName());
		setGroupId(location.getGroupId());
		setPlayerId(location.getPlayerId());
		setSignup(location.getSignup());
		setSignupFactionId(location.getSignupFactionId());
		setCoordinates(location.getCoordinates());
		setLocationUnitList(location.getLocationUnitList());
		setMobileUnitList(location.getMobileUnitList());
	}

	/**
	 * Creates a new Location.
	 * @param iLocation the i location
	 */
	public Location(ILocation iLocation) {
		setId(iLocation.getId());
		setName(iLocation.getName());
		setGroupId(iLocation.getGroupId());
		setPlayerId(iLocation.getPlayerId());
		setSignup(iLocation.getSignup());
		setSignupFactionId(iLocation.getSignupFactionId());
		setCoordinates(iLocation.getCoordinates());
		setLocationUnitList(iLocation.getLocationUnitList());
		setMobileUnitList(iLocation.getMobileUnitList());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the group id.
	 * @return the group id.
	 */
	public int getGroupId() {
		return groupId;
	}

	/**
	 * Returns the player id.
	 * @return the player id.
	 */
	public int getPlayerId() {
		return playerId;
	}

	/**
	 * Returns the signup.
	 * @return the signup.
	 */
	public LocationSignup getSignup() {
		return signup;
	}

	/**
	 * Returns the signup faction id.
	 * @return the signup faction id.
	 */
	public int getSignupFactionId() {
		return signupFactionId;
	}

	/**
	 * Returns the coordinates.
	 * @return the coordinates.
	 */
	public int[] getCoordinates() {
		return coordinates;
	}

	/**
	 * Returns the location unit list.
	 * @return the location unit list.
	 */
	public List<IUnitCount> getLocationUnitList() {
		return locationUnitList;
	}

	/**
	 * Returns the mobile unit list.
	 * @return the mobile unit list.
	 */
	public List<IUnitCount> getMobileUnitList() {
		return mobileUnitList;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the group id.
	 * @param groupId the group id to set.
	 */
	public void setGroupId(int groupId) {
		this.groupId = groupId;
	}

	/**
	 * Sets the player id.
	 * @param playerId the player id to set.
	 */
	public void setPlayerId(int playerId) {
		this.playerId = playerId;
	}

	/**
	 * Sets the signup.
	 * @param signup the signup to set.
	 */
	public void setSignup(LocationSignup signup) {
		this.signup = signup;
	}

	/**
	 * Sets the signup faction id.
	 * @param signupFactionId the signup faction id to set.
	 */
	public void setSignupFactionId(int signupFactionId) {
		this.signupFactionId = signupFactionId;
	}

	/**
	 * Sets the coordinates.
	 * @param coordinates the coordinates to set.
	 */
	public void setCoordinates(int[] coordinates) {
		this.coordinates = coordinates;
	}

	/**
	 * Sets the location unit list.
	 * @param locationUnitList the location unit list to set.
	 */
	public void setLocationUnitList(List<IUnitCount> locationUnitList) {
		this.locationUnitList = locationUnitList;
	}

	/**
	 * Sets the mobile unit list.
	 * @param mobileUnitList the mobile unit list to set.
	 */
	public void setMobileUnitList(List<IUnitCount> mobileUnitList) {
		this.mobileUnitList = mobileUnitList;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(673, 37);
		hash.append(id);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof Location) {
			Location compare = (Location) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ILocation compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (name != null) {
			string.append("name", name);
		}
		string.append("groupId", groupId);
		string.append("playerId", playerId);
		if (signup != null) {
			string.append("signup", signup);
		}
		string.append("signupFactionId", signupFactionId);
		if (coordinates != null) {
			string.append("coordinates", coordinates);
		}
		if (locationUnitList != null) {
			string.append("locationUnitList", locationUnitList);
		}
		if (mobileUnitList != null) {
			string.append("mobileUnitList", mobileUnitList);
		}
		return string.toString();
	}
}
